<template>
  <van-icon
    :color="value === 1 ? 'orange' : '#777'"
    :name="value === 1 ? 'good-job' : 'good-job-o'"
    @click="onLike"
  />
</template>

<script>
import { addLikeArticle, deleteLikeArticle } from '@/api/user'
export default {
  name: 'likeArticle',
  props: {
    value: {
      type: Number,
      require: true
    },
    articleId: {
      type: [Number, String, Object],
      require: true
    }
  },
  components: {},
  data () {
    return {

    }
  },
  created () {

  },
  methods: {
    async  onLike () {
      if (this.value === 1) {
        await deleteLikeArticle(this.articleId)
      } else {
        await addLikeArticle(this.articleId)
      }
      this.$emit('input', this.value === 1 ? 0 : 1)
    }
  }
}
</script>

<style lang="less" scoped>
</style>
